import request from '@/utils/request';

export interface User {
  id: string;
  email: string;
  firstName: string;
  lastName: string;
  status: 'active' | 'inactive';
  departmentId?: string;
  department?: {
    id: string;
    name: string;
  };
  roles?: Array<{
    id: string;
    name: string;
  }>;
  createdAt: string;
  updatedAt: string;
}

export interface UserListParams {
  page?: number;
  pageSize?: number;
  keyword?: string;
  status?: string;
  departmentId?: string;
}

export interface UserFormData {
  email: string;
  password?: string;
  firstName: string;
  lastName: string;
  status: 'active' | 'inactive';
  departmentId?: string;
  roleIds?: string[];
}

// 获取用户列表
export const getUsers = (params?: UserListParams) => {
  return request.get('/users', { params });
};

// 获取单个用户
export const getUser = (id: string) => {
  return request.get(`/users/${id}`); 
};

// 创建用户
export const createUser = (data: UserFormData) => {
  return request.post('/users', data);
};

// 更新用户
export const updateUser = (id: string, data: Partial<UserFormData>) => {
  return request.put(`/users/${id}`, data);
};

// 删除用户
export const deleteUser = (id: string) => {
  return request.delete(`/users/${id}`);
};

// 批量删除用户
export const batchDeleteUsers = (ids: string[]) => {
  return request.post('/users/batch-delete', { ids });
};

// 重置密码
export const resetPassword = (id: string, newPassword: string) => {
  return request.post(`/users/${id}/reset-password`, { newPassword });
};

// 获取导出数据
export const getUsersExportData = (params?: any) => {
  return request.get('/users/export-data', { params });
};

// 批量导入用户
export const batchImportUsers = (users: any[]) => {
  return request.post('/users/batch-import', { users });
};

// 获取导入模板配置
export const getImportTemplate = () => {
  return request.get('/users/import-template');
};
